//
//  QMQCCityViewController.m
//  QcMedical1
//
//  Created by 仲启明 on 2016/12/21.
//  Copyright © 2016年 jiawen Du. All rights reserved.
//

#import "QMQCCityViewController.h"
#import "QMQCCityModel.h"
#import "QMQCCitySecondViewController.h"
@interface QMQCCityViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *cityArray;
@property (nonatomic, weak) UITableView *tableView;
@end

@implementation QMQCCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
    
    [self setupUI];
}
- (void)loadData
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"province.plist" ofType:nil];
    
    NSArray *dicArray = [NSArray arrayWithContentsOfFile:filePath];
    
    NSMutableArray *cityArray = [NSMutableArray array];
    
    for (NSDictionary *dic in dicArray) {
        
        QMQCCityModel *model = [[QMQCCityModel alloc] init];
        
        [model setValuesForKeysWithDictionary:dic];
        
        [cityArray addObject:model];
    }
    
    self.cityArray = cityArray.copy;
}
- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    self.tableView = tableView;
    
    [self.view addSubview:tableView];
    
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
}


#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.cityArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    QMQCCityModel *model = self.cityArray[indexPath.row];
    
    cell.textLabel.text = model.name;
    
    return cell;

}

#pragma mark
#pragma mark
#pragma mark 选中cell跳转到城市页面

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    QMQCCitySecondViewController *secondVC = [[QMQCCitySecondViewController alloc]init];
    
    secondVC.section = indexPath.row;
    
    [self.navigationController pushViewController:secondVC animated:YES];
}
@end
